package com.nineclock.auth.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

/**
 * json序列化
 */
public class NcOAuthExceptionJacksonSerializer extends StdSerializer<NcOAuth2Exception> {
    public NcOAuthExceptionJacksonSerializer(){
        super(NcOAuth2Exception.class);
    }

    /**
     * 序列化 的格式
     * @param e
     * @param jsonGenerator
     * @param serializerProvider
     * @throws IOException
     */
    @Override
    public void serialize(NcOAuth2Exception e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeObjectField("success",false);
        jsonGenerator.writeObjectField("code",e.getHttpErrorCode());
        jsonGenerator.writeObjectField("message",e.getMessage());
        jsonGenerator.writeEndObject();
    }
}